home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / tex / itrns211.zip / SRC / IYACC.Y < prev    next >
Text File  |  1991-10-12  |  10KB  |  367 lines

  1. %{
  2. /*
  3.  *========================================================================== 
  4.  * Copyright 1991 Avinash Chopde, All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of Avinash Chopde not be used in
  11.  * advertising or publicity pertaining to distribution of the software
  12.  * without specific, written prior permission.
  13.  * Avinash Chopde makes no representations about the suitability of this
  14.  * software for any purpose.
  15.  * It is provided "as is" without express or implied warranty.
  16.  *
  17.  * AVINASH CHOPDE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  18.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
  19.  * IN NO EVENT SHALL AVINASH CHOPDE BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  21.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  22.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23.  * OF THIS SOFTWARE.
  24.  *
  25.  * Author:  Avinash Chopde, 1991
  26.  *        C2 Colonial Drive #4, Andover, MA 01810, USA.
  27.  *
  28.  */
  29.  
  30. static char S_RCSID[] = "$Header: e:/itrans/src/rcs/iyacc.y 1.5 91/10/12 21:54:01 avinash Exp $";
  31.  
  32. #include <stdio.h>
  33. #include "itrans.h"
  34.  
  35. int G_lineno = 1; /* GLOBAL var: used by lex to indicate current line number */
  36.  
  37. #define WORD_LEN    511
  38.  
  39. /* Define a struct to keep track of the components of the letter, and
  40.  * the text representation of the word being parsed.
  41.  */
  42. static struct {
  43.     char word[WORD_LEN+1];
  44.     int curr_letter[WORD_LEN+1]; /* collect tokens regarding this letter here */
  45.     int nolig[WORD_LEN+1];/*collect nolig tokens here (see itrans.h, letter_t)*/
  46.     int curr_letter_n; /* number of tokens in curr_letter */
  47.     int curr_type; /* type of letter - special, vowel, cons, etc */
  48. } S_word;
  49.  
  50. char G_endprev_str[LINELEN]; /* used by ilex.l to  pass string to
  51.                   * process in case of the ENDPREV_TOK
  52.                   */
  53.  
  54. #define ADD_TOKEN(t) {    \
  55.     S_word.nolig[S_word.curr_letter_n] = FALSE;        \
  56.     S_word.curr_letter[S_word.curr_letter_n++] = t;    \
  57.     strcat(S_word.word, yytext);            \
  58. }
  59.  
  60. #define ADD_TOKEN_TYPE(t, typ) {            \
  61.     ADD_TOKEN(t);                    \
  62.     S_word.curr_type = typ;                \
  63. }
  64.  
  65. /* forward declarations (for prototypes) */
  66.  
  67. static void S_init_command();
  68. static void S_end_command();
  69. static void S_init_word();
  70. static void S_end_word();
  71. static void S_end_letter();
  72. static void S_init_letter();
  73. static void S_handle_other(char*);
  74.  
  75. %}
  76.  
  77. %token DUMMY_TOK
  78. /* vowels - A_TOK must be first */
  79. %token A_TOK AA_TOK I_TOK II_TOK U_TOK UU_TOK RI_TOK RII_TOK
  80. %token LI_TOK LII_TOK AY_TOK AAY_TOK AI_TOK O_TOK OO_TOK AU_TOK AM_TOK AHA_TOK
  81. /* consonants */
  82. %token KA_TOK KHA_TOK GA_TOK GHA_TOK NGA_TOK
  83. %token CHA_TOK CHHA_TOK JA_TOK JHA_TOK JNH_TOK
  84. %token TTA_TOK TTHA_TOK DDA_TOK DDHA_TOK NNA_TOK
  85. %token TA_TOK THA_TOK DA_TOK DHA_TOK NA_TOK
  86. %token PA_TOK PHA_TOK BA_TOK BHA_TOK MA_TOK
  87. %token YA_TOK RA_TOK LA_TOK VA_TOK
  88. %token SHA_TOK SHHA_TOK SA_TOK
  89. %token HA_TOK
  90. %token LDA_TOK
  91. %token KSHA_TOK GYA_TOK
  92. /* tamil */
  93. %token NNX_TOK NYA_TOK RRA_TOK
  94. /* additional consonants (PHADOT_TOK must be last - see imap.h) */
  95. %token KADOT_TOK KHADOT_TOK GADOT_TOK DDADOT_TOK DDHADOT_TOK JADOT_TOK
  96. %token PHADOT_TOK
  97. /* specials */
  98. %token RA_HALF_TOK ANUSVARA_TOK CHANDRA_TOK CHANDRA_BN_TOK VIRAAM_TOK
  99. %token AVAGRAHA_TOK
  100. /* aum must be the last token */
  101. %token SRI_TOK AUM_TOK
  102. /* others */
  103. %token BLANK_TOK NEWLINE_TOK NOLIG_TOK COMMAND_TOK ENDPREV_TOK
  104. /* languages, ILANG and ENDLANG must bracket all language tokens... */
  105. %token ILANG_TOK MARATHI_TOK HINDI_TOK TAMIL_TOK BENGALI_TOK TELUGU_TOK
  106. %token MALAYALAM_TOK GUJARATI_TOK ORIYA_TOK KANNADA_TOK SANSKRIT_TOK
  107. %token ENDLANG_TOK SETIFM_TOK SETFONT_TOK
  108.  
  109. %start intext
  110.  
  111. %%
  112.  
  113. intext        : 
  114.  
  115.         | intext SETIFM_TOK    {setifm($2, yytext);}
  116.  
  117.         | intext SETFONT_TOK    {setfontcmd($2, yytext);}
  118.  
  119.         | intext
  120.           language      {process_istart($2);}
  121.               dinput
  122.           ENDLANG_TOK    {process_iend();}
  123.         ;
  124.  
  125. language    : MARATHI_TOK        {$$ = MARATHI_TOK;}
  126.         | HINDI_TOK        {$$ = HINDI_TOK;}
  127.         | ILANG_TOK        {$$ = ILANG_TOK;}
  128.         | TAMIL_TOK        {$$ = TAMIL_TOK;}
  129.         | SANSKRIT_TOK        {$$ = SANSKRIT_TOK;}
  130.         | BENGALI_TOK        {$$ = BENGALI_TOK;}
  131.         | TELUGU_TOK        {$$ = TELUGU_TOK;}
  132.         | MALAYALAM_TOK        {$$ = MALAYALAM_TOK;}
  133.         | GUJARATI_TOK        {$$ = GUJARATI_TOK;}
  134.         | ORIYA_TOK        {$$ = ORIYA_TOK;}
  135.         | KANNADA_TOK        {$$ = KANNADA_TOK;}
  136.         ;
  137.  
  138.  
  139. dinput        :
  140.  
  141.         | dinput        { S_init_word(); }
  142.           word            { S_end_word(); }
  143.  
  144.         | dinput        { S_init_command(); }
  145.           command        { S_end_command(); }
  146.  
  147.         | dinput spaces
  148.         | dinput ENDPREV_TOK    { S_handle_other(G_endprev_str);}
  149.  
  150.         | error
  151.         ;
  152.  
  153. word        : oletter        { S_end_letter(); }
  154.         | word oletter        { S_end_letter(); }
  155.         | word ENDPREV_TOK    { S_end_letter();
  156.                       S_handle_other(G_endprev_str);}
  157.         ;
  158.  
  159. oletter        : letter
  160.         | special        { ADD_TOKEN_TYPE($1, SPECIAL_TYPE); }
  161.         ;
  162.  
  163. letter        : vowel            { ADD_TOKEN_TYPE($1, VOWEL_TYPE); }
  164.  
  165.         | consonants vowel    { ADD_TOKEN($2);}
  166.  
  167.         | consonants        { /*
  168.                        * all consonants must end in
  169.                        * a vowel.
  170.                        * Assume vowel is Half-Form
  171.                        * here.
  172.                        */
  173.                       ADD_TOKEN( HALF_FORM );
  174.                     }
  175.  
  176. consonants    : consonant
  177.                 { ADD_TOKEN_TYPE($1, CONSONANT_SINGLE_TYPE);}
  178.  
  179.         | consonants consonant
  180.                 { ADD_TOKEN_TYPE($2, CONSONANT_DOUBLE_TYPE);}
  181.  
  182.         | consonants NOLIG_TOK
  183.                 { S_word.nolig[S_word.curr_letter_n-1] = TRUE;}
  184.  
  185.         ;
  186.  
  187. vowel        : A_TOK
  188.         | AA_TOK
  189.         | I_TOK
  190.         | II_TOK
  191.         | U_TOK
  192.         | UU_TOK
  193.         | RI_TOK
  194.         | RII_TOK
  195.         | LI_TOK
  196.         | LII_TOK
  197.         | AY_TOK
  198.         | AAY_TOK
  199.         | AI_TOK
  200.         | O_TOK
  201.         | OO_TOK
  202.         | AU_TOK
  203.         | AM_TOK
  204.         | AHA_TOK
  205.         ;
  206.  
  207. consonant    : KA_TOK   |   KHA_TOK   |   GA_TOK   |   GHA_TOK   |   NGA_TOK
  208.         | CHA_TOK  |   CHHA_TOK  |   JA_TOK   |   JHA_TOK   |   JNH_TOK
  209.         | TTA_TOK  |   TTHA_TOK  |   DDA_TOK  |   DDHA_TOK  |   NNA_TOK
  210.         | TA_TOK   |   THA_TOK   |   DA_TOK   |   DHA_TOK   |   NA_TOK
  211.         | PA_TOK   |   PHA_TOK   |   BA_TOK   |   BHA_TOK   |   MA_TOK
  212.         | YA_TOK   |   RA_TOK    |   LA_TOK   |   VA_TOK
  213.         | SHA_TOK  |   SHHA_TOK  |   SA_TOK
  214.         | HA_TOK
  215.         | LDA_TOK
  216.         | KSHA_TOK |   GYA_TOK
  217.         | NNX_TOK  |   NYA_TOK   |   RRA_TOK
  218.         | KADOT_TOK|   KHADOT_TOK|   GADOT_TOK|   JADOT_TOK|  PHADOT_TOK
  219.         | DDADOT_TOK|  DDHADOT_TOK
  220.         ;
  221.  
  222. special        : RA_HALF_TOK | ANUSVARA_TOK | VIRAAM_TOK
  223.         | CHANDRA_TOK | CHANDRA_BN_TOK | AVAGRAHA_TOK
  224.         | SRI_TOK     | AUM_TOK
  225.         ;
  226.  
  227. command        : COMMAND_TOK        { process_command(yytext); }
  228.  
  229. spaces        : space
  230.         | spaces space
  231.         ;
  232.  
  233. space        : BLANK_TOK        { process_space(); }
  234.         | NEWLINE_TOK        { process_newline(); }
  235.         ;
  236.  
  237. %%
  238. /*========================================================================== */
  239. /* redefining yyerror to print out yytext, lineno, etc */
  240. yyerror(s) char*s; {
  241.     fprintf(stderr,"(%s) Error at/after line %d,  before word (%s) Seen (%s)\n",
  242.         s, G_lineno, yytext, S_word.word);
  243. }
  244.  
  245. /*========================================================================== */
  246. /*
  247.  * Internal functions
  248.  */
  249.  
  250. static void S_init_word()
  251. {
  252.     /* send the previous word output to process_init_word() */
  253.     process_init_word(S_word.word);
  254.     S_word.word[0] = '\0';
  255.     S_init_letter();
  256.  
  257. }
  258.  
  259. static void S_init_letter()
  260. {
  261.     /*
  262.     fprintf(stderr, "INIT_LETTER\n");
  263.     */
  264.     S_word.curr_letter_n = 0;
  265. }
  266. static void S_end_word()
  267. {
  268.     process_end_word(S_word.word);
  269. }
  270.  
  271. /* S_handle_other is called on a ENDPREV_TOK---ilex.l gives that
  272.  * token when a punctuation, etc is seen.
  273.  * This implies that the current word, if any must be output before
  274.  * outputting the chars in yytext.
  275.  */
  276. static void S_handle_other(char* inp)
  277. {
  278.     int i, j;
  279.     j = strlen(inp);
  280.     for (i = 0; i < j; i ++) {
  281.     process_otherchar(inp[0]);
  282.     }
  283. }
  284.  
  285. static void S_init_command()
  286. {
  287.     /* NOTHING */
  288. }
  289. static void S_end_command()
  290. {
  291.     /* NOTHI